package CodeThree;

import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeMap;

/** @author ASUS */
public class Studentships {
  public static void main(String[] args) {
    TreeMap<Integer, Integer> results = new TreeMap<>(Comparator.comparingInt(integer -> integer));
    Scanner inputScanner = new Scanner(System.in);
    int students = inputScanner.nextInt();
    int headcount = inputScanner.nextInt();
    for (int i = 1; i <= students; i++) {
      results.put(i, inputScanner.nextInt());
    }
    for (int i = 0; i < headcount; i++) {
      char deletion = inputScanner.next().charAt(0);
      int serialnumber = inputScanner.nextInt();
      int devalue = inputScanner.nextInt();
      if (deletion == 'U') {
        results.put(serialnumber, devalue);
      } else if (deletion == 'Q') {
        System.out.printf("%d ", maxResult(results, serialnumber, devalue));
      }
    }
  }

  /** 返回TreeMap中从start到end索引最大值 */
  private static int maxResult(TreeMap<Integer, Integer> results, int starting, int ending) {
    int maturest = 0;
    for (int i = starting; i <= ending; i++) {
      maturest = Math.max(maturest, results.get(i));
    }
    return maturest;
  }
}
